var medArr = new Array();//医保类型所有的数据
var fundArr = new Array()//基金类型所有的数据
var medSelect = new Array();
var fundSelect = new Array();
var depCompareConfig = {} ; // 科室周监测配置-科室对照关系
var depAllConfig = [] ; // 保存所有对照科室
var depOldConfig = [] ; // 保存原科室
var flag = 0;
$(function(){
	$('input[name="switch"]').lc_switch();
	// LC-switch change事件
//	$('#'+tabId+' #collapseDotime,#collapseIsBelongToDep,#isScoreShow .row div').delegate('.lcs_check', 'lcs-statuschange', function() {
	$('#'+tabId+' #collapseIsBelongToDep,#isScoreShow .row div').delegate('.lcs_check', 'lcs-statuschange', function() {
	    var status = ($(this).is(':checked')) ? 1 : 0 ;
	    $(this).val(status) ;
	});
	
	$('#'+tabId+' .icon-asterisk').css({"font-size": "xx-small","color": "red","padding": "10px"});
	getRoleValue();//获取系统角色信息
	getDictionaryValue();//获取字典值
	// 重启分组服务
	restartDrgsGroup() ;
	//获取医嘱开单科室
	getOrderDep();
	
	$("#"+tabId+" .date-from").datetimepicker({
		   format: "yyyy-mm-dd",
	       autoclose: true,
	       todayBtn: true,
	       minView: 2,
	       startView:2,
	       language: 'zh-CN'
	   });
	$("#"+tabId+" .date-to").datetimepicker({
	       format: "yyyy-mm-dd",
	       autoclose: true,
	       todayBtn: true,
	       minView: 3,
	       startView:2,
	       language: 'zh-CN'
	   });
	/**
	 * 是否分页
	 */
	$('#'+tabId+' #dataPager input[type="radio"]').iCheck({
		checkboxClass: 'icheckbox_square-blue',
	    radioClass: 'iradio_square-blue',
	    increaseArea: '20%' // optional
	});
	/**
	 * 分层配置
	 */
	$('#'+tabId+' #collapseSix input').iCheck({
		checkboxClass: 'icheckbox_square-blue',
	    radioClass: 'iradio_square-blue',
	    increaseArea: '20%' // optional
	});
	
	/**
	 * 分组
	 */
	$('#'+tabId+' #collapseSeven input[type="checkbox"]').iCheck({
		checkboxClass: 'icheckbox_square-blue',
	    radioClass: 'iradio_square-blue',
	    increaseArea: '20%' // optional
	});
	/**
	 * 导出权限
	 */
	$('#'+tabId+' #dataExp input[type="checkbox"]').iCheck({
		checkboxClass: 'icheckbox_square-blue',
	    radioClass: 'iradio_square-blue',
	    increaseArea: '20%' // optional
	});
	
	/**
	 * 未入组病例再分组是否开启
	 */
	$('#'+tabId+' input[name="groupingAgain"]').iCheck({
		checkboxClass: 'icheckbox_square-blue',
	    radioClass: 'iradio_square-blue',
	    increaseArea: '20%' // optional
	});

	
});

/**
 * 
 * @@param year
 * @void
 * @ Discription:获取调整费用比例
 * @configPage.js
 */
function getgetStdAvgFee(stdId,adjust,type){	
	if(paramsDataTables==undefined){
		paramsDataTables={};
	}
	var paramsDataTables={};
	paramsDataTables.searching=false;
	paramsDataTables.paging=false;
	paramsDataTables.lengthChange=false;
	paramsDataTables.info=false;
	paramsDataTables.scrollY='250px';
	paramsDataTables.dom='<"top"fl>rt<"bottom"ip><"clear">';
	$.post(contextPath + "/systemConfig/getStdAvgFee.dhc",{"stdId":stdId,"adjust":adjust}).done(function(result){
		if (result.success) {
			if(type==1){
				drgUI.success("查询结果已根据调整比例计算，点击提交生效！");
			}
			var data = result.data;
			var columns = [{
						"data" : "AS_DRG_CODE",
						"title" : "DRG代码"
					}, {
						"data" : "PRIMEVAL_AVG_FEE",
						"title" : "年度次均费用"
					}, {
						"data" : "AS_AVG_FEE",
						"title" : "调整后次均费用"
					}];
			$('#' + tabId + ' #thirteen_id').dataTableBasic(columns, data,paramsDataTables);
		}else{
			if(type==1){
				drgUI.success("查询失败！")
			}				
		}
	})
};

/**
 * 获取字典值并装在页面
 */
function getDictionaryValue(){
		var medData = diction.MED_INS_TYPE;// 医保类型选择的数据
		var fundData = diction.FUND_TYPE;//基金类型选择的数据
		for(var i = 0;i<medData.length;i++){
			if(medData[i].DICVALUE){
				var arr = {"medValue":medData[i].DICVALUE,"medDesc":medData[i].DICDESC};
				medArr.push(arr);
				medSelect.push(arr);
			}
		}
		for(var i = 0;i<fundData.length;i++){
			var arr = {"fundValue":fundData[i].DICVALUE,"fundDesc":fundData[i].DICDESC};
			fundArr.push(arr);
			fundSelect.push(arr);
		}
		//填充页面
		initSystemConfigPage(diction);//初始化系统配置页面
		getHospQuota();//获取医院指标数据

}
/**
 * 获取系统角色信息加载到页面
 */
function getRoleValue(){
	$.ajax({
		url : contextPath + "/auth/role/pagingQuery.dhc",
			data:{"page":0,"pagesize":20},
			type : "post",
			dataType : "json",
			async : false,
			success : function(result) {var roleData = result.data;
		var roleStr = "";
		$.each(roleData,function(n,value){
			roleStr += '<input type="checkbox" name="roleName" style = "display:inline;" value="'+value.name+'">&nbsp;<label>'+value.name+'</label>&nbsp;&nbsp';
		});
		$("#"+tabId+" #dataExp").append(roleStr);}
	})
}
/**
 * 获取医院指标数据
 */
function getHospQuota(){
	$.post(contextPath+"/systemConfig/getHospQuota.dhc").done(function(result){
		if(result.success && result.data && result.data.length>0){
			var data=result.data;
			var hospQuotaStr = "";
			var j=0;
			 for(var i=0; i<data.length; i++){
				 if(i%3==0){
					 j=i;
					 hospQuotaStr += ' <div class="row" style="width:60%; margin-left:30%"> ';
				 }
				 hospQuotaStr += ' <div class="col-md-3"> ' ;
				 if(data[i].MSFLAG==1){
					 hospQuotaStr += '<input type="checkbox" checked ="checked" name="hospQuotaName" style= "display:inline;" value="'+data[i].MSCODE+'">&nbsp;<label>'+data[i].MSDESC+'</label>&nbsp;&nbsp';  
				 }else{
					 hospQuotaStr += '<input type="checkbox" name="hospQuotaName" style= "display:inline;" value="'+data[i].MSCODE+'">&nbsp;<label>'+data[i].MSDESC+'</label>&nbsp;&nbsp';  
				 }
				 hospQuotaStr += ' </div>';
				 if(i==j+2||i==data.length-1){
					 hospQuotaStr += ' </div>';
				 }
			 }
			$("#"+tabId+" #collapseEleven .panel-body").append(hospQuotaStr);
			$('#'+tabId+' #collapseEleven input').iCheck({
				checkboxClass: 'icheckbox_square-blue',
			    radioClass: 'iradio_square-blue',
			    increaseArea: '20%' // optional
			});
		
		}
	});
}
/**
 * 初始化系统配置页面
 * @param dicValue 字典值
 */
function initSystemConfigPage(dicValue){
	//获取分组器版本信息
	$.ajax({
		"dataType" : 'json',
		"type" : "POST",
		"async" : false , // 同步
		dataType: "json",
		"url" : contextPath + '/DRGVersion/findAllVersion.dhc',
		"success" : function(res) {
			var groupVerData = res.data
			var groupVerStr = "";
			groupVerStr += '<option value="">请选择</option>';
			for(var i = 0;i<groupVerData.length;i++)
			{
				groupVerStr += '<option value="'+groupVerData[i].verCode+'">'+groupVerData[i].verDesc+'</option>';
			}
			$("#"+tabId+" #groupVer").append(groupVerStr);
		}
	});
	//测算选用标杆类型
	var stdTypeData = dicValue.AS_STD_TYPE;
	var stdTypeStr = '';
	stdTypeStr += '<option value="">请选择</option>';
	for(var i=0; stdTypeData!=null&&i<stdTypeData.length;i++){
		stdTypeStr += '<option value="'+stdTypeData[i].DICVALUE+'">'+stdTypeData[i].DICDESC+'</option>';
	}
	if(stdTypeData==null || stdTypeData.length==0){
		$('#'+tabId+' #stdType').append(stdTypeStr);
		$('#'+tabId+' #stdType').after('&nbsp;<span><font color="red" size="1">请先配置标杆类型字典</font></span>');
	}else{
		$('#'+tabId+' #stdType').append(stdTypeStr);
	}
	//首页版本
	var medTypeData = dicValue.MED_TYPE;
	var medTypeStr = "";
	for(var i = 0;medTypeData!=null&&i<medTypeData.length;i++){
		medTypeStr += '<input type="radio" class="form-control" name="mrVersion" value="'+medTypeData[i].DICVALUE+'">'+medTypeData[i].DICDESC+' &nbsp;&nbsp;&nbsp;&nbsp;';
	}
	if(medTypeStr==""){
		medTypeStr = "<div><span class='warning'>请先到字典管理页面配置首页版本的字典</span></div>";
		$("#"+tabId+" #MED_TYPE").append(medTypeStr);
	}else{
		$("#"+tabId+" #MED_TYPE").append(medTypeStr);
		
	}
	/**
	 * 是否分页
	 */
	$('#'+tabId+' #collapseOne #MED_TYPE input').iCheck({
		checkboxClass: 'icheckbox_square-blue',
	    radioClass: 'iradio_square-blue',
	    increaseArea: '20%' // optional
	});
	//诊断编码版本
	var optionPlease = "<option value=''>请选择</option>";
	var icdVerData = dicValue.DIA_ICD_VERSION;
	var icdVerStr ='';
	for(var i = 0;icdVerData!=null&&i<icdVerData.length;i++)
	{
		icdVerStr += '<option value="'+icdVerData[i].DICVALUE+'">'+icdVerData[i].DICDESC+'</option>';
	}
	//手术编码版本
	var operVerData = dicValue.OPER_ICD_VERSION;
	var operVerStr = "";
	for(var i = 0;operVerData!=null&&i<operVerData.length;i++)
	{
		operVerStr += '<option value="'+operVerData[i].DICVALUE+'">'+operVerData[i].DICDESC+'</option>';
	}
	if(icdVerStr==''||operVerStr==''){
		var warningInfo = "<div><span class='warning'>请先到字典管理页面配置诊断编码和手术编码的字典</span></div>";
		$("#"+tabId+" #icdVerPanel").append(warningInfo);
		$("#"+tabId+" #ICD_VERSION").append(optionPlease);
		$("#"+tabId+" #OPER_VERSION").append(optionPlease);
		$("#"+tabId+" #drg_icd_version_d").append(optionPlease);
		$("#"+tabId+" #drg_icd_version_o").append(optionPlease);
	}else{
		$("#"+tabId+" #ICD_VERSION").append(optionPlease+icdVerStr);
		$("#"+tabId+" #OPER_VERSION").append(optionPlease+operVerStr);
		$("#"+tabId+" #drg_icd_version_d").append(optionPlease+icdVerStr);
		$("#"+tabId+" #drg_icd_version_o").append(optionPlease+operVerStr);
	}
	
	$("#"+tabId+" input.staticInput").focus(function(){
		$(this).attr("readonly","readonly");
		$(this).prev().find("div").css("display","block");
	});
	$("#"+tabId+" #startMonth").prev().find(".month").click(function(){
		var start = $(this).attr("code");
		var end = 12;
		if(start>1)
			end = start-1;
		$("#"+tabId+" #startMonth").val(start);
		$("#"+tabId+" #endMonth").val(end);
		$("#"+tabId+" .staticMonth").css("display","none");
	});
	$("#"+tabId+" #endMonth").prev().find(".month").click(function(){
		var end = $(this).attr("code")*1;
		var start = 1;
		if(end<12)
			start = end+1;
		$("#"+tabId+" #startMonth").val(start);
		$("#"+tabId+" #endMonth").val(end);
		$("#"+tabId+" .staticMonth").css("display","none");
	});
	
	
	//加载已经配置的数据项
	$.post(contextPath + "/systemConfig/getConfigValue.dhc").done(function(result){
		var configValue = result.data;
		if(configValue.RED_MARK!=undefined && configValue.RED_MARK!="null" && configValue.RED_MARK.length>0){
			var redMarkData=configValue.RED_MARK+"";
			$('#'+tabId+' #redMark_id').val($.trim(redMarkData));
		}
		//科室周检测特殊科室配置
		var dayMonitorData = configValue.DAYMONITOR_DEP;
		if(dayMonitorData!=undefined&&dayMonitorData.length>0){
			var str=dayMonitorData.split('θ');
			configValue.depCompare = {} ;
			if(str.length>0){
				if(str[0].length>0){
					$('#'+tabId+' #dayMoritorOne_id').val(str[0]);
				}
				if(str[1].length>0){
					$('#'+tabId+' #dayMoritorTwo_id').val(str[1]);
				}
				// 妇产科:CKEBQ,CKBQ&综合科:GDWKYBQ,EBHKB
				if(str[2] && str[2].length>0){
					var depCprTemp = str[2].split('&') ;
					for(var o in depCprTemp) {
						var key = depCprTemp[o].substring(0,depCprTemp[o].lastIndexOf(":")) ;
						var value = depCprTemp[o].substring(depCprTemp[o].lastIndexOf(":")+1).split(",") ;
						depCompareConfig[key] = value ;
					}
				}
				// 医保类型配置
			/*	if(str[3] && str[3].length>0){
					$('#'+tabId+' #dayMoritorMedicalType').val(str[3]);
				}*/
				// 第二类有文本则设置科室对照关系
				$('#'+tabId+' #depCompare_id').removeAttr("disabled");
				// 第二类文本域失去焦点,设置按钮状态
				$('#'+tabId+' #dayMoritorTwo_id').blur(function(){
					if(lengthOfSting($(this).val().replace(/\s/g,""))==0) {
						$('#'+tabId+' #depCompare_id').attr("disabled","true");
					} else {
						// 根据第二类文本框内容更新对照列表
						$('#'+tabId+' #depCompare_id').removeAttr("disabled");
						depOldConfig = $('#'+tabId+' #dayMoritorTwo_id').val().split("&") ;
						$('#'+tabId+' #depCompare_id').click() ;
					}
				})
				
				// 原科室名
				depOldConfig = str[1].split("&") ;
				$('#'+tabId+' #depCompare_id').click(function() {
					// 显示下拉列表
					$('#'+tabId+' #depOld').css("display","block") ;
//					$('#'+tabId+' #depOld').prev().css("display","block") ;
					$('#'+tabId+' #depNow').css("display","block")  ;
//					$('#'+tabId+' #depNow').prev().css("display","block")  ;
					$('#'+tabId+' #depOld').empty() ;
					var depOld = "" ;
					for(var o in depOldConfig) {
						depOld += '<option value="'+depOldConfig[o]+'">'+depOldConfig[o]+'</option>';
					}
					$('#'+tabId+' #depOld').append(depOld) ;
					getAllDep("depNow",depCompareConfig[depOldConfig[0]]) ;
				}) ;
				
				// 原科室下拉框切换时更新对照科室
				$('#'+tabId+' #depOld').change(function() {
					getAllDep("depNow",depCompareConfig[$(this).val()]) ;
				})
				
			}
		}
		var medType = configValue.MED_TYPE; //首页版本值
		if(typeof(medType)!='undefined'){
			$('#'+tabId+' #collapseOne input:radio[name="mrVersion"][value="'+medType+'"]').iCheck('check');//设置已选的首页版本选中
		}
		var icdVerType = configValue.ICD_VERSION; //ICD版本值
		if(typeof(icdVerType)!='undefined'){
			$('#'+tabId+' #ICD_VERSION').val(icdVerType);//设置ICD版本选中
		}
		var operVerType = configValue.OPER_VERSION; //手术版本值
		if(typeof(operVerType)!='undefined'){
			$('#'+tabId+' #OPER_VERSION').val(operVerType);//设置手术版本选中
		}
		
		var staticYear = configValue.STATIC_YEAR;
		if(staticYear!=null&&typeof(staticYear)!='undefined'){
			var staticYearArr = staticYear.split("-");
			$('#'+tabId+' #startMonth').val(staticYearArr[0]);
			$('#'+tabId+' #endMonth').val(staticYearArr[1]);
		}
		
		var medInsValues = configValue.MED_INS_TYPE;//基金类型数据
		if(medInsValues!=null&&typeof(medInsValues)!='undefined'){
			var medInsValueArr = medInsValues.split("θ")
			for(var i=0;i<medInsValueArr.length;i++){
				if(i>0){
					var str = "";
					str+=' <div style="margin-top:5px"  class="medInsFundConfig"> ';
					str+=' 	<span>基金类型</span> ';
					str+=' 	<input class=" form-control" name="" style = "width:100px;display:inline"> ';
					str+=' 	<span style="margin-left:25px">医保类型</span> ';
					str+=' 	<input class="yibao form-control " style = "width:300px;display:inline" placeholder = "示例:医保类型1+医保类型2+医保类型3">';
					str+=' 	<span class = "remove" style = "color:#D9534F;cursor: pointer;"><i class="icon-minus-sign"></i></span> ';
					str+=' </div> ';
					$("#"+tabId+" #medInsFundConfig").append(str);
					var medInsValue = medInsValueArr[i];
					var type = medInsValue.split("#")[0];
					var fundText = getFundTextByValue(type);
					removeFundSelectByValue(type);
					var fundTextAndValue=type+"("+fundText+")";
					var value = medInsValue.split("#")[1];
					$('#'+tabId+' #medInsFundConfig>div:last input:eq(0)').attr("name",type);
					$('#'+tabId+' #medInsFundConfig>div:last input:eq(1)').attr("name",value);
					var med_insArr = value.split("&");
					var med_insText = "";//医保类型的文本Text
					
					$.each(med_insArr, function(i,val){   
						var aValue =null;
						removeMedSelectByValue(val);
						aValue = getMedInsTextByValue(val);
						med_insText = med_insText + aValue + "&";
					  });   
					
					med_insText=med_insText.substring(0,med_insText.length-1)
					var med_insTextAndValue = value + "("+med_insText+")";
					$('#'+tabId+' #medInsFundConfig>div:last input:eq(0)').val(fundText);
					$('#'+tabId+' #medInsFundConfig>div:last input:eq(1)').val(med_insText);
				}else{
					var medInsValue = medInsValueArr[i];
					var type = medInsValue.split("#")[0];
					removeFundSelectByValue(type);
					var fundText = getFundTextByValue(type);
					var fundTextAndValue=type+"("+fundText+")";
					var value = medInsValue.split("#")[1];
					var med_insArr = value.split("&");
					var med_insText = "";//医保类型的文本Text
					$.each(med_insArr, function(i,val){   
						var aValue =null;
						removeMedSelectByValue(val);
						aValue = getMedInsTextByValue(val);
						med_insText = med_insText + aValue + "&";
					  });   
					$('#'+tabId+' #medInsFundConfig>div:last input:eq(0)').attr("name",type);
					$('#'+tabId+' #medInsFundConfig>div:last input:eq(1)').attr("name",value);
					med_insText=med_insText.substring(0,med_insText.length-1)
					var med_insTextAndValue = value + "("+med_insText+")";
					$('#'+tabId+' #medInsFundConfig>div input:eq(0)').val(fundText);
					$('#'+tabId+' #medInsFundConfig>div input:eq(1)').val(med_insText);
				}
			}
			medAndFundSelect();
			$("#"+tabId+" #medInsFundConfig .remove").unbind();
			//绑定事件
			$("#"+tabId+" #medInsFundConfig .remove").click(function(){
				var fundVal = $(this).parent().children("input:eq(0)").attr("name");
				var fundText = $(this).parent().children("input:eq(0)").val();
				addFundSelect(fundVal,fundText);
				var medValue = $(this).parent().children("input:eq(1)").attr("name");
				var medDesc =$(this).parent().children("input:eq(1)").val();
				var medVal = medValue.split("&");
				var medText =medDesc.split("&");
				$.each(medVal, function(i,val){   
					addMedSelect(val,medText[i]);
				  });  
				medAndFundSelect();
				$(this).parent().remove();
			});
		}else{
			medAndFundSelect();
		}
        /*外地高权重现住址区县编码前三位配置*/
	    var hiWeightPostCode=configValue.HIW_POSTCODE;
	    if(hiWeightPostCode!=undefined){
	    	$('#'+tabId+' #P00190600_id').val(hiWeightPostCode)
	    }else{
	    	/*默认值110*/
	    }
		var dayMonitor = configValue.DAY_MONITOR;//日监测数据
		if(typeof(dayMonitor)!='undefined'){
			var dayMonitorUrlMethod = dayMonitor.split("θ");
			$('#'+tabId+' #dayMonitorUrl').val(dayMonitorUrlMethod[0]);//日监测数据地址
			$('#'+tabId+' #dayMonitorMethod').val(dayMonitorUrlMethod[1]);//日监测数据方法
		}
		var importOrder = configValue.IMPORT_ORDER;//导入医嘱明细
		if(typeof(importOrder)!='undefined'){
			var importOrderUrlMethod = importOrder.split("θ");
			$('#'+tabId+' #importOrderUrl').val(importOrderUrlMethod[0]);//导入医嘱明细地址
			$('#'+tabId+' #importOrderMethod').val(importOrderUrlMethod[1]);//导入医嘱明细方法
		}
		var drawHisData = configValue.DRAW_HIS_DATA;//抽取编目数据
		if(typeof(drawHisData)!='undefined'){
			var drawHisDataUrlMethod = drawHisData.split("θ");
			$('#'+tabId+' #drawHisDataUrl').val(drawHisDataUrlMethod[0]);//抽取编目数据地址
			$('#'+tabId+' #drawHisDataMethod').val(drawHisDataUrlMethod[1]);//抽取编目数据方法
		}
		var drawYBData = configValue.YIBAO_ADDR;//抽取医保数据
		if(typeof(drawYBData)!='undefined'){
			var drawYBDataUrlMethod = drawYBData.split("θ");
			$('#'+tabId+' #drawYBDataUrl').val(drawYBDataUrlMethod[0]);//抽取医保数据地址
			$('#'+tabId+' #drawYBDataMethod').val(drawYBDataUrlMethod[1]);//抽取医保数据方法
		}
		var operInfo = configValue.OPER_INFO;//导入手术信息
		if(typeof(operInfo)!='undefined'){
			var operInfoUrlMethod = operInfo.split("θ");
			$('#'+tabId+' #operInfoUrl').val(operInfoUrlMethod[0]);//导入手术信息地址
			$('#'+tabId+' #operInfoMethod').val(operInfoUrlMethod[1]);//导入手术信息方法
		}
		var depBedDays = configValue.DEP_BED_DAYS;//导入床日信息
		if(typeof(depBedDays)!='undefined'){
			var depBedDaysUrlMethod = depBedDays.split("θ");
			$('#'+tabId+' #depBedDaysUrl').val(depBedDaysUrlMethod[0]);//导入床日信息地址
			$('#'+tabId+' #depBedDaysMethod').val(depBedDaysUrlMethod[1]);//导入床日信息方法
		}
		var mrq = configValue.MRQ;//首页质控接口推送
		if(typeof(mrq)!='undefined'){
			var mrqUrlMethod = mrq.split("θ");
			$('#'+tabId+' #mrqUrl').val(mrqUrlMethod[0]);//接口推送地址
			$('#'+tabId+' #mrqMethod').val(mrqUrlMethod[1]);//接口推送方法
			$('#'+tabId+' #mrqParam1').val(mrqUrlMethod[2]);//额外参数1
			$('#'+tabId+' #mrqParam2').val(mrqUrlMethod[3]);//额外参数2
		}
		
		var ICDMatchAPI=configValue.ICDMatchAPI;//ICD智能对照API
		if(typeof(ICDMatchAPI)!='undefined'){
			var ICDMatchAPIUrlMethod = ICDMatchAPI.split("θ");
			$('#'+tabId+' #ICDMatchAPIUrl').val(ICDMatchAPIUrlMethod[0]);//地址
			$('#'+tabId+' #ICDMatchAPIMethod').val(ICDMatchAPIUrlMethod[1]);//方法
		}
		var mrStruc = configValue.MR_STRUC;//首页结构化存储
		if(typeof(mrStruc)!='undefined'){
			var mrStrucUrlMethod = mrStruc.split("θ");
			$('#'+tabId+' #mrStrcUrl').val(mrStrucUrlMethod[0]);//接口推送地址
			$('#'+tabId+' #mrStrcParam1').val(mrStrucUrlMethod[1]);//额外参数1
			$('#'+tabId+' #mrStrcParam2').val(mrStrucUrlMethod[2]);//额外参数2
		}
		
		var depLineLayer = configValue.DEP_LINE_LAYER;//科室层次配置
		if(typeof(depLineLayer)!='undefined'){
			var layers = depLineLayer.split(",");
			for(var i=0;i<layers.length-1;i++){
				if(layers[i]==1){
					$('#'+tabId+' #collapseSix input.depLineLayer:checkbox:eq('+i+')').iCheck('check');
				}
			}
		}
		var doctorSet = configValue.DOCTOR_SET;//科室层次配置
		if(typeof(doctorSet)!='undefined'){
			var dset = doctorSet.split(",");
			for(var i=0;i<dset.length;i++){
				if(dset[i]==1){
					$('#'+tabId+' #collapseSix input.doctorSet:checkbox:eq('+i+')').iCheck('check');
				}
			}
		}
		var groupAdder = configValue.GROUP_ADDER;//分组器地址
		if(typeof(groupAdder)!='undefined'){
			$('#'+tabId+' #groupAdder').val(groupAdder);
		}
		var drgICDVersionD = configValue.DRG_ICD_VERSION_D;//诊断对照版本诊断
		if(typeof(drgICDVersionD)!='undefined'){
			$('#'+tabId+' #drg_icd_version_d').val(drgICDVersionD);
		}
		var drgICDVersionO = configValue.DRG_ICD_VERSION_O;//诊断对照手术
		if(typeof(drgICDVersionO)!='undefined'){
			$('#'+tabId+' #drg_icd_version_o').val(drgICDVersionO);
		}
		var groupAdder2016 = configValue.GROUP_ADDER_2016;//2016版分组器地址
		if(typeof(groupAdder2016)!='undefined'){
			$('#'+tabId+' #group2016Adder').val(groupAdder2016);
		}
		var producerThreadCnt = configValue.PRODUCER_THREAD_CNT;//数据组装线程数
		if(typeof(producerThreadCnt)!='undefined'){
			$('#'+tabId+' #producerThreadCnt').val(producerThreadCnt);
		}
		var groupThreadCnt = configValue.GROUP_THREAD_CNT;//数据分组线程数
		if(typeof(groupThreadCnt)!='undefined'){
			$('#'+tabId+' #groupThreadCnt').val(groupThreadCnt);
		}
		
		var groupVer = configValue.GROUP_VER;//分组器版本
		if(typeof(groupVer)!='undefined'){
			$('#'+tabId+' #groupVer').val(groupVer);//设置分组器版本选中
		}
			
		var icdMatch = configValue.ICD_MATCH;//诊断对照
		if(typeof(icdMatch)!='undefined'){
			if(icdMatch == 'true'){
				$('#'+tabId+' #collapseSeven input#icdMatch:checkbox').iCheck('check');//设置诊断对照选中
			}
		}
		var autoGroup = configValue.AUTO_GROUP;//自动分组
		if(typeof(autoGroup)!='undefined'){
			if(autoGroup == 'true'){
				$('#'+tabId+' #collapseSeven input#autoGroup:checkbox').iCheck('check');//设置自动分组选中
			}
		}

		/**
		 * 数据导出权限初始化加载
		 */
		var dataExpRole = configValue.DATA_EXPORT_ROLE;
		if(typeof(dataExpRole)!='undefined'){
			var roleNameChk = dataExpRole.split(",");
			for(var i=0;i<roleNameChk.length;i++){				 
				$('#'+tabId+' input[name="roleName"]:checkbox').each(function(){
					var roleName = $(this).val();
					if(roleNameChk[i] == roleName){
						$(this).attr("checked","checked"); 
						$(this).parent().addClass('checked');
						return;
					}
				});
			}
		}
		/**
		 * 是否分页显示配置初始化加载
		 */
		var pageValue = configValue.PAGEING; 
		if(typeof(pageValue)!='undefined'){
			$('#'+tabId+' #dataPager input:radio[name="pageing"][value="'+pageValue+'"]').iCheck('check');
		}
		
		/**
		 * 是否启用再分组配置初始化加载
		 */
		var groupAgainValue = configValue.GROUPINGAGAIN; 
		if(typeof(groupAgainValue)!='undefined'){
			$('#'+tabId+' input:radio[name="groupingAgain"][value="'+groupAgainValue+'"]').iCheck('check');
		}
		
		/**
		 * 综合得分计算比率
		 */
		var totalScoreValue = configValue.TOTALSCORE; 
		if(typeof(totalScoreValue)!='undefined'){
			var scoreRatio=totalScoreValue.split("θ");
			$('#'+tabId+' #capacityScore_id').val(scoreRatio[0]);
			$('#'+tabId+' #efficiencyScore_id').val(scoreRatio[1]);
			$('#'+tabId+' #qualityScore_id').val(scoreRatio[2]);
			
		}
		
		// 是否属于本科室默认值
		if(Number(configValue.ISBELONGTODEP)) {
			$('#'+tabId+' #isBelongToDepCheck').lcs_on() ;
		} else {
			$('#'+tabId+' #isBelongToDepCheck').lcs_off() ;
		}
		//科主任是否查看全院科室绩效得分
		if(configValue.IS_SCORE_SHOW==1){
			$('#'+tabId+' #isScoreShowCheck').lcs_on();
		}else{
			$('#'+tabId+' #isScoreShowCheck').lcs_off() ;
		}
	})
	$("#"+tabId+" #medInsFundConfig .add").unbind();
	$("#"+tabId+" #medInsFundConfig .remove").unbind();
	//绑定事件
	$("#"+tabId+" #medInsFundConfig .add").click(addMedInsType);
	$("#"+tabId+" #medInsFundConfig .remove").click(function(){
		var fundVal = $(this).parent().children("input:eq(0)").attr("name");
		var fundText = $(this).parent().children("input:eq(0)").val();
		var medValue = $(this).parent().children("input:eq(1)").attr("name");
		var medDesc =$(this).parent().children("input:eq(1)").val();
		if(medDesc!=""){
			addFundSelect(fundVal,fundText);
			var medVal = medValue.split("&");
			var medText =medDesc.split("&");
			$.each(medVal, function(i,val){   
				addMedSelect(val,medText[i]);
			  });  
			medAndFundSelect();
			$(this).parent().remove();
		}
	});
	
}
/**
 * 根据code 获取费用大类名称
 * @param code
 */
function getCostClass(code){
	var desc = "";
	switch(code){
	case "nurs":
		desc = "护理";
	break;
	case "drug":
		desc = "药品";
	break;
	case "tech":
		desc = "医技";
	break;
	case "med":
		desc = "医疗";
	break;
	case "manag":
		desc = "管理";
	break;
	}
	return desc;
}
/**
 * 根据code 获取费用类别名称
 * @param code
 */
function getCostCate(costCateData,code){
	var option = "";
	option = option + "<select class='form-control'>";
	option = option + "<option value =''>请选择</option>"
	for(var i = 0;i < costCateData.length;i++){
		if(code == costCateData[i].DICVALUE){
			option = option + "<option value ='"+costCateData[i].DICVALUE+"' selected='selected'>"+costCateData[i].DICDESC+"</option>"
		}
		option = option + "<option value ='"+costCateData[i].DICVALUE+"'>"+costCateData[i].DICDESC+"</option>"
	}
	option = option + "</select>";
	return option;	
}
/**
 * 添加医保基金类型的方法
 */
function addMedInsType(){
	var fundVal = $('#'+tabId+' #fund_type_select').val();//基金类型的value
	var fundText = $('#'+tabId+' #fund_type_select').find("option:selected").text();//基金类型的文本Text
	if(fundVal == null || fundVal == undefined || fundVal == "" ){
		drgUI.warning("请选择相应的基金！");
		return;
	}
	removeFundSelectByValue(fundVal);
	var arr = $('#'+tabId+' #med_ins_type_slect').val();
	if(arr == null || arr == undefined || arr == "" ){
		drgUI.warning("请选择相应的医保！");
		return;
	}
	var med_insText = "";//医保类型的文本Text
	$.each(arr, function(i,val){   
		var aValue =null;
		removeMedSelectByValue(val);
		aValue = getMedInsTextByValue(val);
		med_insText = med_insText + aValue + "&";
	  });   
	medAndFundSelect();
	med_insText=med_insText.substring(0,med_insText.length-1);
	var med_insVal = arr.join("&");//医保类型的value
	$('#'+tabId+' .medInsFundConfig').each(function(){
		var fundValue=$(this).find('input:eq(0)').val();
		var medsValue=$(this).find('input:eq(1)').val();
		if(fundValue==""||medsValue==""){
		$(this).remove();	
		}
	});
	var str = "";
	str+=' <div style="margin-top:5px" class="medInsFundConfig"> ';
	str+=' 	<span>基金类型</span> ';
	str+=' 	<input class="form-control" name="'+fundVal+'" style = "width:100px;display:inline" value="'+fundText+'"> ';
	str+=' 	<span style="margin-left:25px">医保类型</span> ';
	str+=' 	<input class="form-control" name="'+med_insVal+'" style = "width:300px;display:inline" value="'+med_insText+'">';
	str+=' 	<span class = "remove" style = "color:#D9534F;cursor: pointer;"><i class="icon-minus-sign"></i></span> ';
	str+=' </div> ';
	$("#"+tabId+" #medInsFundConfig").append(str);
	$("#"+tabId+" #medInsFundConfig .remove").unbind();
	$("#"+tabId+" #medInsFundConfig .remove").click(function(){
		var fundVal = $(this).parent().children("input:eq(0)").attr("name");
		var fundText = $(this).parent().children("input:eq(0)").val();
		addFundSelect(fundVal,fundText);
		var medValue = $(this).parent().children("input:eq(1)").attr("name");
		var medDesc =$(this).parent().children("input:eq(1)").val();
		var medVal = medValue.split("&");
		var medText =medDesc.split("&");
		$.each(medVal, function(i,val){   
			addMedSelect(val,medText[i]);
		  });  
		medAndFundSelect();
		$(this).parent().remove();
	});
}
/**
 * 保存系统配置
 */
function saveSystemConfig(){
	var configList = [];
	
	var HIW_POSTCODE=$('#'+tabId+' #P00190600_id').val();
	if(typeof(HIW_POSTCODE)=="undefined"){
		drgUI.warning('请填写外地高权重现居住地址邮政编码前三位!');
		return;
	}else{
        var reg=/^\+?\d{3}$/;
        if(!reg.test(HIW_POSTCODE)){
	    		drgUI.warning('编码为整数且必须为3位!');
	    		return;
	      }
	}
	
	//科室周周监测特殊科室配置
//	depCompareConfig[$('#'+tabId+' #depOld').val()] = $('#'+tabId+' #depNow').val() ;
	var depCompareValue = "" ;
	for(var o in depOldConfig) {
		var temp = "" ;
		if(depCompareConfig[depOldConfig[o]]) {
			depCompareValue += depOldConfig[o]  ;
			depCompareValue += ":"  ;
			depCompareValue += depCompareConfig[depOldConfig[o]] ;
			depCompareValue += "&" ;
		}
	}
	depCompareValue = depCompareValue.substring(0,depCompareValue.lastIndexOf("&")) ;
	var DAYMONITOR_DEP= $.trim($('#'+tabId+' #dayMoritorOne_id').val())+"θ"+ $.trim($('#'+tabId+' #dayMoritorTwo_id').val()) + "θ" + depCompareValue;
	configList.push({cfg_code:"DAYMONITOR_DEP",cfg_desc:"科室周周监测特殊科室",cfg_value:DAYMONITOR_DEP,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"科室周周监测特殊科室"});
	
	$.post(contextPath+"/systemConfig/syncDepartment.dhc",{"depInfo":depCompareValue}).done(function(){})
	
	configList.push({cfg_code:"HIW_POSTCODE",cfg_desc:"外地高权重现居住地址邮政编码前三位",cfg_value:HIW_POSTCODE,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"外地高权重现居住地址邮政编码前三位"});
	
	var medType=$('#'+tabId+' input:radio[name="mrVersion"]:checked').val();//首页版本
	if(typeof(medType)=="undefined"){
		drgUI.warning('请选择首页版本!');
		return;
	}
	configList.push({cfg_code:"MED_TYPE",cfg_desc:"首页版本",cfg_value:medType,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"首页版本"});
	var icdVer = $('#'+tabId+' #ICD_VERSION').val();//诊断编码版本
	if(icdVer==""){
		drgUI.warning('请选择诊断编码版本!');
		return;
	}
	configList.push({cfg_code:"ICD_VERSION",cfg_desc:"诊断编码版本",cfg_value:icdVer,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"诊断编码版本"});
	var operVer = $('#'+tabId+' #OPER_VERSION').val();//手术编码版本
	if(operVer==""){
		drgUI.warning('请选择手术编码版本!');
		return;
	}
	configList.push({cfg_code:"OPER_VERSION",cfg_desc:"手术编码版本",cfg_value:operVer,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"手术编码版本"});
	
	var medInsType = "";//基金类型 (不做非空判断)
	var medInsBool = false;//默认没问题
	$('#'+tabId+' #medInsFundConfig>div').each(function(){
		var type = jQuery.trim($(this).find("input:eq(0)").attr("name"));//基金类型
		var value = jQuery.trim($(this).find("input:eq(1)").attr("name"));//基金类型值
		if(type==""||value=="")
		{medInsBool=true;}//有问题
		medInsType += type+"#"+value+"θ";
	});
	medInsType = medInsType.substring(0,medInsType.length-1); 
	if(!medInsBool){
		configList.push({cfg_code:"MED_INS_TYPE",cfg_desc:"基金类型",cfg_value:medInsType,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"基金类型"});
	}
	var startMonth = $("#"+tabId+" #startMonth").val();//开始月份
	var endMonth = $("#"+tabId+" #endMonth").val();//结束月份
	if(startMonth==""||endMonth==""){
		drgUI.warning('请将选择开始月份和结束月份!');
		return;
	}
	var staticYear = startMonth+"-"+endMonth;//统计年度
	configList.push({cfg_code:"STATIC_YEAR",cfg_desc:"统计年度",cfg_value:staticYear,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"统计年度"});
	/*	var uniBenchmark = $('#'+tabId+' input#input-benchmark:checkbox').is(':checked');//统一标杆
	configList.push({cfg_code:"UNI_BENCHMARK",cfg_desc:"统一标杆",cfg_value:uniBenchmark,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"统一标杆"});*/
	
	var dayMonitorUrlMethod = $("#"+tabId+" #dayMonitorUrl").val()+"θ"+$("#"+tabId+" #dayMonitorMethod").val();//日监测数据地址+方法
	configList.push({cfg_code:"DAY_MONITOR",cfg_desc:"日监测数据",cfg_value:dayMonitorUrlMethod,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"日监测数据"});
	var importOrderUrlMethod = $("#"+tabId+" #importOrderUrl").val()+"θ"+$("#"+tabId+" #importOrderMethod").val();//导入医嘱明细地址+方法
	configList.push({cfg_code:"IMPORT_ORDER",cfg_desc:"导入医嘱明细",cfg_value:importOrderUrlMethod,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"导入医嘱明细"});
	

	var mrStrcUrlMethod =  $("#"+tabId+" #mrStrcUrl").val()+"θ"+$("#"+tabId+" #mrStrcParam1").val()+"θ"+$("#"+tabId+" #mrStrcParam2").val();//首页质控接口推送地址+方法+参数1,参数2
	configList.push({cfg_code:"MR_STRUC",cfg_desc:"首页结构化存储",cfg_value:mrStrcUrlMethod,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"首页结构化存储数据抽取接口"});
	
	
	var drawHisDataUrlMethod = $("#"+tabId+" #drawHisDataUrl").val()+"θ"+$("#"+tabId+" #drawHisDataMethod").val();//抽取编目数据地址+方法
	configList.push({cfg_code:"DRAW_HIS_DATA",cfg_desc:"抽取编目数据",cfg_value:drawHisDataUrlMethod,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"抽取编目数据"});
	var drawYBDataUrlMethod = $("#"+tabId+" #drawYBDataUrl").val()+"θ"+$("#"+tabId+" #drawYBDataMethod").val();//抽取医保数据地址+方法
	configList.push({cfg_code:"YIBAO_ADDR",cfg_desc:"抽取医保数据",cfg_value:drawYBDataUrlMethod,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"抽取医保数据"});
	var operInfoUrlMethod = $("#"+tabId+" #operInfoUrl").val()+"θ"+$("#"+tabId+" #operInfoMethod").val();//导入手术信息地址+方法
	configList.push({cfg_code:"OPER_INFO",cfg_desc:"导入手术信息",cfg_value:operInfoUrlMethod,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"导入手术信息"});
	var depBedDaysUrlMethod = $("#"+tabId+" #depBedDaysUrl").val()+"θ"+$("#"+tabId+" #depBedDaysMethod").val();//抽取医保数据地址+方法
	configList.push({cfg_code:"DEP_BED_DAYS",cfg_desc:"导入床日信息",cfg_value:depBedDaysUrlMethod,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"导入床日信息"});
	var mrqUrlMethod =  $("#"+tabId+" #mrqUrl").val()+"θ"+$("#"+tabId+" #mrqMethod").val()+"θ"+$("#"+tabId+" #mrqParam1").val()+"θ"+$("#"+tabId+" #mrqParam2").val();//首页质控接口推送地址+方法+参数1,参数2
	configList.push({cfg_code:"MRQ",cfg_desc:"首页质控推送",cfg_value:mrqUrlMethod,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"首页质控接口推送"});
	
	var ICDMatchAPIUrlMethod =  $("#"+tabId+" #ICDMatchAPIUrl").val()+"θ"+$("#"+tabId+" #ICDMatchAPIMethod").val();//ICD智能对照API
	configList.push({cfg_code:"ICDMatchAPI",cfg_desc:"ICD智能对照",cfg_value:ICDMatchAPIUrlMethod,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"ICD智能对照"});
	
	var doctorSet = "";//医师选择配置
	$('#'+tabId+' input.doctorSet:checkbox').each(function(){
		if(true == $(this).is(':checked')){
			doctorSet += "1,"
		}
		else
		{
			doctorSet += "0,"
		}
	});
	doctorSet = doctorSet.substring(0,doctorSet.length-1); 
	configList.push({cfg_code:"DOCTOR_SET",cfg_desc:"医师选择配置",cfg_value:doctorSet,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"医师选择配置"});
	
	var depLineLayer = "";//科室分层配置
	$('#'+tabId+' input.depLineLayer:checkbox').each(function(){
		if(true == $(this).is(':checked')){
			depLineLayer += "1,"
		}else{
			depLineLayer += "0,"
		}
	});
	if(doctorSet.indexOf("1")>-1)
	{
		depLineLayer += "1"
	}else{
		depLineLayer += "0"
	}
	// 科室和病区至少选中其中一个!
	if(depLineLayer.substring(2,5) == "0,0") {
		drgUI.warning('科室和病区至少选中其中一个!');
		return;
	}
	configList.push({cfg_code:"DEP_LINE_LAYER",cfg_desc:"科室分层配置",cfg_value:depLineLayer,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"科室分层配置"});
	
	var groupAdder = jQuery.trim($('#'+tabId+' #groupAdder').val());//分组器地址
	var group2016Adder = jQuery.trim($('#'+tabId+' #group2016Adder').val());//分组器2016版地址
	var groupVer = jQuery.trim($('#'+tabId+' #groupVer').val());//分组器版本
	var groupVerDesc=$('#'+tabId+' #groupVer option:selected').text(); 
	
	if(groupAdder==""&& group2016Adder==""){
		drgUI.warning('请至少配置一种分组器!');
		return;
	}
	//16之前分组器
	if(groupAdder!=""){
		configList.push({cfg_code:"GROUP_ADDER",cfg_desc:"分组器地址",cfg_value:groupAdder,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"分组器地址"});
	}
	var producerThreadCnt = jQuery.trim($('#'+tabId+' #producerThreadCnt').val())//数据组装线程数
	if(producerThreadCnt==""){
		drgUI.warning('请配置数据组装线程数!');
		return;
	}else if(producerThreadCnt>19){
		drgUI.warning('数据组装线程数请配置为小于等于19的整数');
		return;
	}
	configList.push({cfg_code:"PRODUCER_THREAD_CNT",cfg_desc:"数据组装线程数",cfg_value:producerThreadCnt,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"数据组装线程数"});
	
	var groupThreadCnt= jQuery.trim($('#'+tabId+' #groupThreadCnt').val());//数据分组线程数
	if(groupThreadCnt==""){
		drgUI.warning('请配置数据分组线程数!');
		return;
	}else if(groupThreadCnt>19){
		drgUI.warning('数据分组线程数请配置为小于等于19 的整数!');
		return;
	}
	configList.push({cfg_code:"GROUP_THREAD_CNT",cfg_desc:"数据分组线程数",cfg_value:groupThreadCnt,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"数据分组线程数"});
	if(group2016Adder!=""){
		configList.push({cfg_code:"GROUP_ADDER_2016",cfg_desc:"2016版分组器地址",cfg_value:group2016Adder,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"分组器地址"});
	}
	if(!groupVer){
		drgUI.warning('请配置分组器版本!');
		return;
	}
	configList.push({cfg_code:"GROUP_VER",cfg_desc:"分组器版本",cfg_value:groupVer,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"分组器版本"});

	var icdMatch = $('#'+tabId+' input#icdMatch:checkbox').is(':checked');//诊断对照
	configList.push({cfg_code:"ICD_MATCH",cfg_desc:"诊断对照",cfg_value:icdMatch,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"诊断对照"});
	var autoGroup = $('#'+tabId+' input#autoGroup:checkbox').is(':checked');//自动分组
	configList.push({cfg_code:"AUTO_GROUP",cfg_desc:"自动分组",cfg_value:autoGroup,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"自动分组"});
	//ICD对照版本控制诊断
	var drgICDVersionD = $("#"+tabId+" #drg_icd_version_d").val();
	configList.push({cfg_code:"DRG_ICD_VERSION_D",cfg_desc:"ICD对照版本_诊断",cfg_value:drgICDVersionD,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"ICD对照版本_诊断"});
	//ICD对照版本控制手术
	var drgICDVersionO = $("#"+tabId+" #drg_icd_version_o").val();
	configList.push({cfg_code:"DRG_ICD_VERSION_O",cfg_desc:"ICD对照版本_手术",cfg_value:drgICDVersionO,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"ICD对照版本_手术"});
	
	var dataExpOfRole = "";//数据导出权限配置
	$('#'+tabId+' input[name="roleName"]:checked').each(function(){		
			dataExpOfRole += $(this).val() + ',';
	});
	if(dataExpOfRole==""){
		drgUI.warning('请在表格配置一栏中配置数据导出权限!');
		return;
	}
	configList.push({cfg_code:"DATA_EXPORT_ROLE",cfg_desc:"数据导出权限",cfg_value:dataExpOfRole,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"对系统现有各角色进行数据导出权限配置"});
	//保存指标配置
	$('#'+tabId+' input[name="hospQuotaName"]').each(function(i,n){
		
		if($(this).attr("checked")){
			$.post(contextPath+"/systemConfig/updateHospQuota.dhc",{"dataHospQuote":$(this).val(),"flag":"1"}).done(function(){})

		}else{
			$.post(contextPath+"/systemConfig/updateHospQuota.dhc",{"dataHospQuote":$(this).val(),"flag":"0"}).done(function(){})

		}
	});

	var pageValue=$('#'+tabId+' input:radio[name="pageing"]:checked').val();//首页版本
	if(typeof(pageValue)=="undefined"){
		drgUI.warning('请选择系统数据显示是否分页!');
		return;
	}
	configList.push({cfg_code:"PAGEING",cfg_desc:"是否分页",cfg_value:pageValue,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"系统datatables数据是否分页配置"});
    var score=$('#'+tabId+' #capacityScore_id').val()+"θ"+$('#'+tabId+' #efficiencyScore_id').val()+"θ"+$('#'+tabId+' #qualityScore_id').val();
	configList.push({cfg_code:"TOTALSCORE",cfg_desc:"综合得分计算比率",cfg_value:score,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"综合得分计算比率"});
	var array_of_checked_values =  $("#"+tabId+" .multiple").multiselect("getChecked").map(function(){
		return this.value; 
		}).get();
	
	var redMark=$('#'+tabId+' #redMark_id').val().length>0 ? $.trim($('#'+tabId+' #redMark_id').val()):"";
	configList.push({cfg_code:"RED_MARK",cfg_desc:"医保红冲过滤配置",cfg_value:redMark,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"医保红冲过滤配置"});
	
	//费用分段特殊部门配置
	saveOrderSpecialDep();
	
	var groupAgainValue=$('#'+tabId+' input:radio[name="groupingAgain"]:checked').val();//未入组病例再分组是否开启
	
	configList.push({cfg_code:"GROUPINGAGAIN",cfg_desc:"未入组病例再分组是否开启",cfg_value:groupAgainValue,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"系统分组后，未入组病例再分组是否开启配置"});
	//提交系统定时任务
//	var daymonitorStr = $('#'+tabId+' #dayMonitor_id').val() ;
//	var isOperStr = $('#'+tabId+' #isOper_id').val() ;
//	var sumcostStr = $('#'+tabId+' #sumcost_id').val() ;
//	var chechdataStr = $('#'+tabId+' #checkdata_quality_id').val() ;
//	var dotimestr=daymonitorStr+"θ"+isOperStr+"θ"+sumcostStr+"θ"+chechdataStr;
//	configList.push({cfg_code:"DOTIMEDTASK",cfg_desc:"定时任务管理(科室周检测，手术操作，计算费用，数据质量监测)",cfg_value:dotimestr,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"定时任务管理(科室周检测，手术操作，计算费用，数据质量监测)"});
	
	// 是否属于本科室配置(配置后,绩效分析，科室指标检测，病组指标检测页面钻取到医师页面时提示不属于钻取科室的医师)
//	console.log($('#'+tabId+' #isBelongToDepCheck').val()) ;
	configList.push({cfg_code:"ISBELONGTODEP",cfg_desc:"是否属于本科室开关",cfg_value:$('#'+tabId+' #isBelongToDepCheck').val(),cfg_valid:"1",cfg_isdic:"0",cfg_resume:"是否属于本科室开关"}) ;
	//科主任是否查看全院科室绩效得分
	var isScoreShow = $('#'+tabId+' #isScoreShowCheck').val();
	configList.push({cfg_code:"IS_SCORE_SHOW",cfg_desc:"科主任是否查看全院科室绩效得分",cfg_value:isScoreShow,cfg_valid:"1",cfg_isdic:"0",cfg_resume:"科主任是否查看全院科室绩效得分部分内容"})
	
	
	$.post(contextPath + "/systemConfig/saveSystemConfig.dhc",{"configs":JSON.stringify(configList)}).done(function(result){
		if(result.success) {
			drgUI.success('配置成功!');
		}else{
			drgUI.warning('配置失败,请检查日志!');
			return;
		}
	});
	//保存费用分段特殊部门配置
	saveOrderSpecialDep();
}
/**
 * 重启分组服务
 */
function restartDrgsGroup() {
	$("#" + tabId + " #restart").click(function(){
		var filePath = $.trim($("#" + tabId + " #filePath").val());
		restart() ;
		function restart(){
			$("#" + tabId + " #restart").attr("disabled","disabled" ) ;
			$.post(contextPath + "/restartService/start.dhc",{"filePath":filePath},function(result){
				$("#" + tabId + " #restart").removeAttr("disabled");
				var msg = result.data ;
				if(result.hasErrors) {
					var msg = result.errorMessage ;
					drgUI.error(msg);
				} else {
					var msg = result.data ;
					drgUI.success(msg);
				}
			});
		}
	});
}


//根据医保类型的value查询对应的Text(既：根据医保类型的值查询医保类型的名称)
function getMedInsTextByValue(value){
	var medInsText = null;
	for(var i in medArr){
        if (medArr.hasOwnProperty(i)) { 
        	if(medArr[i].medValue == value){
        		medInsText = medArr[i].medDesc;
        	}
        };
    }
	
	return medInsText;
}

//根据基金类型的value查询对应的Text(既：根据基金类型的值查询基金类型的名称)
function getFundTextByValue(value){
	var fundText = null;
	for(var i in fundArr){
        if (fundArr.hasOwnProperty(i)) { //filter,只输出man的私有属性
        	if(fundArr[i].fundValue == value){
        		fundText = fundArr[i].fundDesc;
        	}
        };
    }
	return fundText;
}

//根据医保类型的value移除对应的medSelect中的值
function removeMedSelectByValue(value){
	for(var i in medSelect){
        if (medSelect.hasOwnProperty(i)) { 
        	if(medSelect[i].medValue == value){
        		medSelect.splice(i,1); 
        	}
        };
    }
	
}

//根据医保类型的value添加对应的medSelect中的值
function addMedSelect(value,text){
	var arr = {"medValue":value,"medDesc":text}
	medSelect.push(arr);
}

//根据医保类型的value添加对应的fundSelect中的值
function addFundSelect(value,text){
	var arr = {"fundValue":value,"fundDesc":text}
	fundSelect.push(arr);
}
//根据基金类型的value移除对应的fundSelect中的值
function removeFundSelectByValue(value){
	for(var i in fundSelect){
        if (fundSelect.hasOwnProperty(i)) { 
        	if(fundSelect[i].fundValue == value){
        		fundSelect.splice(i,1); 
        	}
        };
    }
}


/**
 * 重新绘制多选下拉框
 */
function medAndFundSelect(){
	var medStr="";
	var fundStr = "";
	$("#med_ins_type_slect").remove();
	
	$(".multiselect-native-select").remove();
	$("#medInsFundConfig").children("span:eq(1)").after("<select id='med_ins_type_slect' style='width:200px;' class='multiselect' multiple='multiple'></select>");
	for(var i = 0;i<medSelect.length;i++){
		 medStr = medStr + '<option value="'+medSelect[i].medValue+'">'+medSelect[i].medDesc+'</option>';
	}
	//医保类型选着多选下拉框初始化
	$("#"+tabId+" #med_ins_type_slect").html("");
	$("#"+tabId+" #med_ins_type_slect").append(medStr);
	
	for(var i = 0;i<fundSelect.length;i++){
		fundStr = fundStr + '<option value="'+fundSelect[i].fundValue+'">'+fundSelect[i].fundDesc+'</option>';
	}
	//多选下拉框初始化
	$("#"+tabId+" #fund_type_select").html("");
	$("#"+tabId+" #fund_type_select").append(fundStr);
		$("#"+tabId+" .multiselect").multiselect({
			includeSelectAllOption: true ,
			selectAllText: '全部选择' ,
			allSelectedText: '全部选择'
		});
		
	flag++;
}
/**
 * 
 * @ Discription:费用分段特殊部门配置-获取医嘱开单科室
 * @Autor ：WENYI
 * 2017年8月10日上午9:24:38
 */
function getOrderDep(){
	$.post(contextPath+"/systemConfig/getOrderDep.dhc",function(result){
		var orderDepData=result.data;
		var availableLeftData=[];//保存可选的数据，开单医嘱科室以及描述都有时，可选
		var availableRightData=[];//右边列表数据
		for(var o in orderDepData){
			if(orderDepData[o].ISSPECIAL==1){//判断是否为特殊部门,如是，则添加到右边列表中
				availableRightData.push(orderDepData[o]);
			}
			else{
				availableLeftData.push(orderDepData[o]);
			}
		}
		//调用双向选择列表
		selectListCustom($('#'+tabId+' #orderDep_id'),availableLeftData,availableRightData,'DEPCODE','DEPDESC');
		if(orderDepData.length==0){
			$('#'+tabId+' #orderDep_warining_id').html('<span class="zhujie"><strong>提示</strong>：请先导入医嘱明细，再进行配置。</span>');
		}
	});
}
/**
 * 
 * @ Discription:保存医嘱开单科室-特殊部门
 * @Autor ：WENYI
 * 2017年8月10日上午10:08:41
 */
function saveOrderSpecialDep(){
	//判断是否有选中的数据
//	if($('#'+tabId+' #orderDep_id .list-body .right-box .item').length==0){
//		return;
//	}
	var deps='';
	$('#'+tabId+' #orderDep_id .list-body .right-box .item').each(function(){
		deps+=$(this).attr('data-value')+',';
	});
	$.post(contextPath+'/systemConfig/saveSpecialDep.dhc',{deps:deps.substring(0,deps.length-1)},function(result){
		if(result.hasErrors){
			drgUI.error('费用分段特殊部门配置提交失败!');
		}
	});
}



/**
 * 获取所有科室信息
 */
function getAllDep(selectId,depSelected){	
	var initialiseSelect = function (selectId,depSelected) {
		var optStr = "";
		for(var i = 0;i<depAllConfig.length;i++)
		{
			optStr = optStr + '<option value="'+depAllConfig[i].depCode+'">'+depAllConfig[i].depName+'</option>';
		}
		//多选下拉框初始化
		$("#"+tabId+" #"+selectId+"").empty();
		$("#"+tabId+" #"+selectId+"").multiselect('destroy') ;
		$("#"+tabId+" #"+selectId+"").append(optStr);
		$("#"+tabId+" #"+selectId+"").multiselect({
			includeSelectAllOption: true  ,
			selectAllText: '全选选择' ,
			allSelectedText: '全部选择',
			enableFiltering: true,
            maxHeight: 150, 
            dropRight: true ,
            onChange: function(element, checked) {
            	depCompareConfig[$('#'+tabId+' #depOld').val()] = $('#'+tabId+' #depNow').val() ;
            }
		});
		
		// 设置选中状态
		if(depSelected && depSelected.length >0) {
			$("#"+tabId+" #"+selectId+"").multiselect('select', depSelected);
		}
	}
		//获取所有科室列表
		$.ajax({
			url : contextPath + "/Department/findAllDep.dhc",
			type : "post",
			dataType : "json",
			async : false,
			success : function(result) {
				depAllConfig = result.data;
				initialiseSelect(selectId,depSelected) ;
			}
		});		
}
